﻿using System;
using System.Collections.Generic;
using System.IO;
using BSDS.Commands.Commands;
using BSDS.Commands.Commands.Creation.Implementation;
using BSDS.Core.Infrastructure.Logging;
using BSDS.Core.Model.Services;
using BSDS.Core.Model.Services.Geocoding;
using BSDS.Core.Model.Services.Jobs;
using BSDS.Core.Model.Services.Uploading;

namespace BSDS.Service.Commands
{
    public class ServiceGeocodingCommandCreator : GeocodeCommandCreator
    {
        public ServiceGeocodingCommandCreator(GeocodingService geoService, AccountService accountService, DataRepository dataRepository, 
            JobRepository jobRepository, JobService jobService, UploadService uploadService, Logger logger) 
            : base(geoService, accountService, dataRepository, jobRepository, jobService, uploadService, logger)
        {
        }

        protected override ICommand Create(Dictionary<string, string> parameters)
        {
            var defaultConfig = CreateConfiguration(parameters);

            defaultConfig.StoreInOutputFile = true;
            defaultConfig.OutputFilename = "..\\geocoded\\" + AppendDate(defaultConfig.InputFilename);
            
            return Create(defaultConfig);
        }

        private static string AppendDate(string filename)
        {
            return Path.GetFileNameWithoutExtension(filename) +
                   DateTime.Now.ToString("_yyyyMMddHHmmss") +
                   Path.GetExtension(filename);
        }
    }
}